package com.offer;


import com.utils.DataUtils;

import java.util.HashMap;
import java.util.PriorityQueue;

public class Test40 {

    public int[] getLeastNumbers(int[] arr, int k) {
        int[] result = new int[k];

        PriorityQueue<Integer> integerPriorityQueue = new PriorityQueue<>();

        for (int temp : arr) {
            integerPriorityQueue.offer(temp);
        }

        for (int i = 0; i < k; i++) {
            result[i] = integerPriorityQueue.poll();
        }
        return result;
    }

    public static void main(String[] args) {


        Test40 test34 = new Test40();
        int[] result = test34.getLeastNumbers(new int[]{4, 9, 3, 2, 19, 5}, 3);
        DataUtils.printArray(result);
    }

}
